// 柯里化, 将函数改造成可以多次调用单个函数的形式,  好处就是可以减少重复传递的不变参数
//  应用场景 
function curry(fn) {
    let len = fn.length;

    return function curriedFn(...args) {
        if (args.length == len) {
            fn(...args)
        } else {
            return function (...newArgs) {
                let a = args.concat(newArgs);
                curriedFn(...a)
            }
        }
    }
}


const sum = (a, b) => {
    let result = a + b;
    console.log(result)
}

const curriedSum = curry(sum)(1);

curriedSum(2)
curriedSum(5)